package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


public class OrderConfirmVo implements Serializable {
    // 收货地址，ums_member_receive_address 表
    @Setter @Getter
    private List<MemberAddressVo> addresses;
    // 购物清单，根据购物车页面传递过来的 skuIds 查询
    @Setter @Getter
    private List<OrderItemVo> items;
    // 可用积分，ums_member 表中的 integration 字段
    @Setter @Getter
    private Integer integration;

    private Integer count;

    private BigDecimal total;

    private BigDecimal payPrice;
    @Setter @Getter
    private Map<Long,Boolean> stocks;

    // 订单令牌，防止重复提交
    @Setter @Getter
    private String orderToken;

    public BigDecimal getTotal(){
        BigDecimal sum=new BigDecimal(0);
        if(items!=null) {
            for (OrderItemVo item : items) {
                sum=sum.add(item.getPrice().multiply(new BigDecimal(item.getCount())));
            }
        }
        return sum;
    }

    public BigDecimal getPayPrice(){
        BigDecimal sum=new BigDecimal(0);
        if(items!=null) {
            for (OrderItemVo item : items) {
                sum=sum.add(item.getPrice().multiply(new BigDecimal(item.getCount())));
            }
        }
        return sum;
    }

    public Integer getCount(){
        int cnt=0;
        if(items!=null) {
            for (OrderItemVo item : items) {
                cnt+=item.getCount();
            }
        }
        return cnt;
    }
}
